package com.wmc.sqltransformweb.config;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

import java.io.IOException;

/**
 * @auther wangmingchang
 * @date 2019/11/25 09:36
 */
@Log4j2
@Configuration
public class AutoBrowerConfiguration {

    @Value("${server.port}")
    private String serverPort;

    @EventListener({ApplicationReadyEvent.class})
    void applicationReadyEvent() {
        log.info("应用已经准备就绪 ... 启动浏览器");
        // 这里需要注url:端口号+测试类方法名
        String url = "http://localhost:" + serverPort;
        Runtime runtime = Runtime.getRuntime();
        try {
            runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
        } catch (IOException e) {
            log.error("启动浏览器异常", e);
        }

    }
}
